/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.message;

import javax.sip.address.URI;
import javax.sip.header.*;
import javax.sip.message.MessageFactory;
import javax.sip.message.Request;
import javax.sip.message.Response;
import java.text.ParseException;
import java.util.List;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class MessageFactoryImpl implements MessageFactory {
    /**
     * Creates a new Request message of type specified by the method paramater,
     * containing the URI of the Request, the mandatory headers of the message
     * with a body in the form of a Java object and the body content type.
     *
     * @param requestURI  the new URI object of the requestURI value of this Message.
     * @param method      the new string of the method value of this Message.
     * @param callId      the new CallIdHeader object of the callId value of this Message.
     * @param cSeq        the new CSeqHeader object of the cSeq value of this Message.
     * @param from        the new FromHeader object of the from value of this Message.
     * @param to          the new ToHeader object of the to value of this Message.
     * @param via         the new List object of the ViaHeaders of this Message.
     * @param contentType the new ContentTypeHeader object of the content type
     *                    value of this Message.
     * @param content     the new Object of the body content value of this Message.
     * @return the newly created Request object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the method or the body.
     */
    public Request createRequest(URI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, ContentTypeHeader contentType, Object content) throws ParseException {
        final SIPRequest request = new SIPRequest();
        request.setRequestURI(requestURI);
        request.setMethod(method);
        request.setHeader(callId);
        request.setHeader(cSeq);
        request.setHeader(from);
        request.setHeader(to);
        for (Object viaHeader : via)
            request.addHeader((ViaHeader) viaHeader);
        request.setHeader(maxForwards);
        if (content != null)
            request.setContent(content, contentType);
        return request;
    }

    /**
     * Creates a new Request message of type specified by the method paramater,
     * containing the URI of the Request, the mandatory headers of the message
     * with a body in the form of a byte array and body content type.
     *
     * @param requestURI  the new URI object of the requestURI value of this Message.
     * @param method      the new string of the method value of this Message.
     * @param callId      the new CallIdHeader object of the callId value of this Message.
     * @param cSeq        the new CSeqHeader object of the cSeq value of this Message.
     * @param from        the new FromHeader object of the from value of this Message.
     * @param to          the new ToHeader object of the to value of this Message.
     * @param via         the new List object of the ViaHeaders of this Message.
     * @param contentType the new ContentTypeHeader object of the content type
     *                    value of this Message.
     * @param content     the new byte array of the body content value of this Message.
     * @return the newly created Request object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the method or the body.
     */
    public Request createRequest(URI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, ContentTypeHeader contentType, byte[] content) throws ParseException {
        return createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards, contentType, content);
    }

    /**
     * Creates a new Request message of type specified by the method paramater,
     * containing the URI of the Request, the mandatory headers of the message.
     * This new Request does not contain a body.
     *
     * @param requestURI the new URI object of the requestURI value of this Message.
     * @param method     the new string of the method value of this Message.
     * @param callId     the new CallIdHeader object of the callId value of this Message.
     * @param cSeq       the new CSeqHeader object of the cSeq value of this Message.
     * @param from       the new FromHeader object of the from value of this Message.
     * @param to         the new ToHeader object of the to value of this Message.
     * @param via        the new List object of the ViaHeaders of this Message.
     * @return the newly created Request object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the method.
     */
    public Request createRequest(URI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards) throws ParseException {
        return createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards, null, (Object) null);
    }

    /**
     * Create a new SIP Request object based on a specific string value. This
     * method parses the supplied string into a SIP Request. The request
     * string should only consist of the SIP portion of the Request and not
     * the content.  Supplying a null argument creates an empty SIP Request
     * which may be used to end out "keep alive" messages for a connection.
     *
     * @param request the new string value of the Request.
     * @return the newly created Request object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the request.
     */
    public Request createRequest(String request) throws ParseException {
        return SIPRequest.createLazily(request.getBytes());
    }

    /**
     * Creates a new Response message of type specified by the statusCode
     * paramater, containing the mandatory headers of the message with a body
     * in the form of a Java object and the body content type.
     *
     * @param statusCode  the new integer of the statusCode value of this Message.
     * @param callId      the new CallIdHeader object of the callId value of this Message.
     * @param cSeq        the new CSeqHeader object of the cSeq value of this Message.
     * @param from        the new FromHeader object of the from value of this Message.
     * @param to          the new ToHeader object of the to value of this Message.
     * @param via         the new List object of the ViaHeaders of this Message.
     * @param contentType the new ContentTypeHeader object of the content type
     *                    value of this Message.
     * @param content     the new Object of the body content value of this Message.
     * @return the newly created Response object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the statusCode or the body.
     */
    public Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, ContentTypeHeader contentType, Object content) throws ParseException {
        return null;
    }

    /**
     * Creates a new Response message of type specified by the statusCode
     * paramater, containing the mandatory headers of the message with a body
     * in the form of a byte array and the body content type.
     *
     * @param statusCode  the new integer of the statusCode value of this Message.
     * @param callId      the new CallIdHeader object of the callId value of this Message.
     * @param cSeq        the new CSeqHeader object of the cSeq value of this Message.
     * @param from        the new FromHeader object of the from value of this Message.
     * @param to          the new ToHeader object of the to value of this Message.
     * @param via         the new List object of the ViaHeaders of this Message.
     * @param contentType the new ContentTypeHeader object of the content type
     *                    value of this Message.
     * @param content     the new byte array of the body content value of this Message.
     * @return the newly created Response object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the statusCode or the body.
     */
    public Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, ContentTypeHeader contentType, byte[] content) throws ParseException {
        return null;
    }

    /**
     * Creates a new Response message of type specified by the statusCode
     * paramater, containing the mandatory headers of the message. This new
     * Response does not contain a body.
     *
     * @param statusCode the new integer of the statusCode value of this Message.
     * @param callId     the new CallIdHeader object of the callId value of this Message.
     * @param cSeq       the new CSeqHeader object of the cSeq value of this Message.
     * @param from       the new FromHeader object of the from value of this Message.
     * @param to         the new ToHeader object of the to value of this Message.
     * @param via        the new List object of the ViaHeaders of this Message.
     * @return the newly created Response object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the statusCode.
     */
    public Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards) throws ParseException {
        return null;
    }

    /**
     * Creates a new Response message of type specified by the statusCode
     * paramater, based on a specific Request with a new body in the form of a
     * Java object and the body content type. Only the required headers are
     * copied from the Request.
     *
     * @param statusCode  the new integer of the statusCode value of this Message.
     * @param request     the received Reqest object upon which to base the Response.
     * @param contentType the new ContentTypeHeader object of the content type
     *                    value of this Message.
     * @param content     the new Object of the body content value of this Message.
     * @return the newly created Response object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the statusCode or the body.
     */
    public Response createResponse(int statusCode, Request request, ContentTypeHeader contentType, Object content) throws ParseException {
        return null;
    }

    /**
     * Creates a new Response message of type specified by the statusCode
     * paramater, based on a specific Request with a new body in the form of a
     * byte array and the body content type. Only the required headers are
     * copied from the Request.
     *
     * @param statusCode  the new integer of the statusCode value of this Message.
     * @param request     the received Reqest object upon which to base the Response.
     * @param contentType the new ContentTypeHeader object of the content type
     *                    value of this Message.
     * @param content     the new byte array of the body content value of this Message.
     * @return the newly created Response object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the statusCode or the body.
     */
    public Response createResponse(int statusCode, Request request, ContentTypeHeader contentType, byte[] content) throws ParseException {
        return null;
    }

    /**
     * Creates a new Response message of type specified by the statusCode
     * paramater, based on a specific Request message. This new Response does
     * not contain a body. Only the required headers are copied from the
     * Request.
     *
     * @param statusCode the new integer of the statusCode value of this Message.
     * @param request    the received Reqest object upon which to base the Response.
     * @return the newly created Response object.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the statusCode.
     */
    public Response createResponse(int statusCode, Request request) throws ParseException {
        return null;
    }

    /**
     * Creates a Response from a String. This method parses the supplied string
     * into a SIP Response. The response string should only consist of the
     * SIP portion of the Response and not the content.
     *
     * @param response is a string representing the response. The argument should
     *                 only contain the Sip Headers and not the body of the response.
     * @throws java.text.ParseException which signals an error has been reached unexpectedly
     *                                  while parsing the response.
     * @since v1.2
     */
    public Response createResponse(String response) throws ParseException {
        return null;
    }
}
/*
 * $Log$
 */